package com.ly.mpayment.rest.system;

import java.math.BigDecimal;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.core.Context;

import com.ly.mpayment.persist.hibernate.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.auth0.jwt.JWT;
import com.auth0.jwt.interfaces.DecodedJWT;
import com.ly.mpayment.core.secuity.MD5;
import com.ly.mpayment.core.util.BigUtil;
import com.ly.mpayment.core.util.Config;
import com.ly.mpayment.core.util.CookieRedis;
import com.ly.mpayment.core.util.DateUtils;
import com.ly.mpayment.core.util.JsonUtils;
import com.ly.mpayment.core.util.MapUtil;
import com.ly.mpayment.core.util.ResultMessage;
import com.ly.mpayment.core.util.TokenUtils;
import com.ly.mpayment.core.util.UserUtil;
import com.ly.mpayment.persist.entity.DownShopInfo;
import com.ly.mpayment.persist.entity.ProvincialInformation;
import com.ly.mpayment.persist.entity.UpShopInfo;
import com.ly.mpayment.persist.entity.User;
import com.ly.mpayment.persist.entity.UserLoginLog;
import com.ly.mpayment.persist.service.downshopinfo.IDownShopInfoService;
import com.ly.mpayment.persist.service.provincialinformation.IProvincialInformationService;
import com.ly.mpayment.persist.service.upshopinfo.IUpShopInfoService;
import com.ly.mpayment.persist.service.user.IUserService;
import com.ly.mpayment.persist.service.userloginlog.IUserLoginLogService;
import com.ly.mpayment.rest.AbsRest;
import com.ly.mpayment.rest.recharge.IpUtil;

import cn.jpush.api.utils.StringUtils;
import net.sf.json.JSONObject;

@Component
@Path("system/user/")
public class UserRest extends AbsRest {

	@Autowired
	IUserService userService;

	@Autowired
	IUserLoginLogService logUserService;

	@Autowired
	IProvincialInformationService proService;

	@Autowired
	IDownShopInfoService downService;

	@Autowired
	IUpShopInfoService upService;

	/**
	 * 系统管理员登录
	 * @param data
	 * @param request
	 * @return
	 */
	@POST
	@Path("login")
	public String login(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, "phonenum", "password");
		if (result == null) {
			JSONObject json = JsonUtils.converToJson(data);
			User user = this.userService.findOneUser(json.getString("phonenum"));
			if (user != null) {
				if (user.getPassword().equals(json.getString("password")) && user.getPassword() != null && !user.getPassword().isEmpty()) {
					user.setLastlogintime(DateUtils.getNowDate());
					this.userService.updateUser(user);
					user = this.userService.findByUserid(user.getUseruuid());
					user.setToken(TokenUtils.createToken(user.getUseruuid(), user.getLastlogintime().getTime()+""));
					user.setExpire(DateUtils.addMinutes(Config.TOKEN_TIME, user.getLastlogintime()));
					this.userService.updateUser(user);
					// 添加日志
			     	UserLoginLog log = new UserLoginLog();
					log.setUser(user);
					log.setLoginip(IpUtil.getIp(request));
					log.setRemark(Config.loginStr);
					logUserService.addUserLoginLog(log);

					return ResultMessage.getSucceed( JsonUtils.excludes(user,
							new String[] { "downorderlogs", "downprologs", "upshoppros", "upshopinfos",
									"platformaccountrecords", "matchingstrategies", "recharges", "userloginlogs",
									"uprechargerecords", "downshopproducts", "downrechargeflows", "upgamerecharges",
									"password", "wechatid", "errorCodesForUseruuid", "userstatus", "account",
									"downshopinfo", "remark", "lastlogintime", "createtime", "", "phonenum", "", "" }));
				}
				return ResultMessage.getFailt(ResultMessage.loginError);
			}
			return ResultMessage.getFailt(ResultMessage.loginError);
		}
		return result;
	}

	@POST
	@Path("updateUserPassword")
	public String updateUserPassword(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data,request,userService,"useruuid", "oldpassword", "newpassword");
		if (result == null) {
			JSONObject json = JsonUtils.converToJson(data);
			User user = this.userService.findByUserid(json.getString("useruuid"));
			if (user != null) {
				if (user.getPassword().equals(json.getString("oldpassword"))) {
					user.setPassword(json.getString("newpassword"));
					this.userService.updateUser(user);
					return ResultMessage.getSucceed(null);
				} else {
					return ResultMessage.getFailt(ResultMessage.oldPasswordError);
				}
			}
			return ResultMessage.getFailt(ResultMessage.LOGINNOTUSER);
		}
		return result;
	}

	@POST
	@Path("addUser")
	public  String addUser(String data, @Context HttpServletRequest request) {
		String result = this.validationParameterGetRole( request, userService );
		if (result == null) {
			JSONObject json = JsonUtils.converToJson(data);
			switch (json.getInt("usertype")) {
			case 3:
			case 5:
				// 添加下游渠道商
				result = this.validationParameter(data, "downshopip", "credit", "provinceuuid", "merchantcredit",
						"downshopnum");
				ProvincialInformation info = this.proService.findById(json.getString("provinceuuid"));
				if (result == null && info != null) {
					DownShopInfo shop = null;
					shop = new DownShopInfo();
					User user = null;
					user = new User();
					if (!StringUtils.isEmpty(json.getString("password"))
							&& !StringUtils.isEmpty(json.getString("phonenum"))
							&& !StringUtils.isEmpty(json.getString("username"))) {
						user.setPassword(json.getString("password"));
						user.setPhonenum(json.getString("phonenum"));
						user.setUsername(json.getString("username"));
					}
					user.setUsername(json.getString("username"));
					user.setUsertype(json.getInt("usertype"));
					user.setRemark(json.getString("remark"));
					user.setUserstatus(Config.publicStatus[1]);
					user.setWechatid(json.containsKey("wechatid") ? json.getString("wechatid") : "");
					shop.setDownkey(MD5.md5(user.getPhonenum().concat(DateUtils.getNowDateToString())));
					shop.setDownshopip(json.getString("downshopip"));
					shop.setDownshopnum(json.getString("downshopnum"));
					shop.setDownshopbalance(BigDecimal.ZERO);
					shop.setMerchantcredit(BigUtil.getBigDecimal(json.getString("merchantcredit")));
					shop.setProvincialInformation(info);
					shop.setStatus(Config.productStatus[1]);
					shop.setCallNum(Integer.valueOf(CookieRedis.get("callNnm")));
					shop.setCredit(BigUtil.getBigDecimal(json.getString("credit")));
					shop.setUser(user);
					shop.setOrderCallAddress(json.getString("orderCallAddress"));
					shop.setNoticeBalance(BigUtil.getBigDecimal(json.getString("noticeBalance")));
					shop.setTotalMoney(BigDecimal.ZERO);
					// 检查ip是否重复
					if (this.downService.findShopIp(json.getString("downshopip")) == null) {
						// 检查商家名称 和商家编号是否存在
						if (this.userService.findUserName(json.getString("username")) == null) {
//							if (this.downService.findShopNum(json.getString("downshopnum")) == null) {
								// 检查手机号码是否已经存在
								if (this.userService.findOneUser(json.getString("phonenum")) == null) {
									if (this.downService.addDownShopInfo(shop, user)) {
										return ResultMessage.getSucceed(null);
									}
									return ResultMessage.getFailt("");
								}
								return ResultMessage.getFailt(ResultMessage.addUserError);
//							}
//							return ResultMessage.getFailt(ResultMessage.addShopNumError);
						}
						return ResultMessage.getFailt(ResultMessage.addShopNameError);
					}
					return ResultMessage.getFailt(ResultMessage.addShopIpError);
				}
				return result == null ? ResultMessage.getFailt(ResultMessage.parameterError) : result;
			case 4:
				// 添加上游渠道商
				result = this.validationParameter(data, "upshopip","appId", "upkey", "provinceuuid", "shopnum","orderCommitAddress","queryBalanceAddress","orderStatusAddress");
				info = this.proService.findById(json.getString("provinceuuid"));
				if (result == null && info != null) {
					UpShopInfo shop = null;
					shop = new UpShopInfo();
					User user = null;
					user = new User();
					if (!StringUtils.isEmpty(json.getString("password"))
							&& !StringUtils.isEmpty(json.getString("phonenum"))
							&& !StringUtils.isEmpty(json.getString("username"))) {
//						user.setPassword(json.getString("password"));
						user.setPhonenum(json.getString("phonenum"));
						user.setUsername(json.getString("username"));
					}
					user.setUsername(json.getString("username"));
					user.setUsertype(json.getInt("usertype"));
					user.setRemark(json.getString("remark"));
					user.setUserstatus(Config.publicStatus[1]);
					user.setWechatid(json.containsKey("wechatid") ? json.getString("wechatid") : "");

					shop.setUpkey(json.getString("upkey"));
					shop.setAppId(json.getString("appId"));
					shop.setUpshopip(json.getString("upshopip"));
					shop.setShopnum(json.getString("shopnum"));
					shop.setProvincialInformation(info);
					shop.setStatus(true);
					shop.setOrderCommitAddress(json.getString("orderCommitAddress"));
//					shop.setQueryBalanceAddress(json.getString("queryBalanceAddress"));
					shop.setOrderStatusAddress(json.getString("orderStatusAddress"));
					shop.setOrderCallAddress(json.getString("orderCallAddress"));
					shop.setUpshopbalance(BigDecimal.ZERO);
					shop.setTotalMoney(BigDecimal.ZERO);
					shop.setRepeatNum(json.getInt("repeatNum"));
					//默认都不开启
					shop.setArtificial(false);
					shop.setPressOrder(false);
					shop.setQuerySwitch(false);
					shop.setNoticeSwitch(false);
					shop.setNoticeBalance(BigUtil.getBigDecimal(json.getString("noticeBalance")));
					// 检查ip是否重复
//					if (this.upService.findShopIp(json.getString("upshopip")) == null) {
						// 检查商家名称 和商家编号是否存在
						if (this.userService.findUserName(json.getString("username")) == null) {
//							if (this.upService.findShopNum(json.getString("shopnum")) == null) {
								// 检查手机号码是否已经存在
//								if (this.userService.findOneUser(json.getString("phonenum")) == null) {
									if (this.upService.addUpshopinfo(shop, user)) {
										return ResultMessage.getSucceed(null);
									}
									return ResultMessage.getFailt("");
//								}
//								return ResultMessage.getFailt(ResultMessage.addUserError);
//							}
//							return ResultMessage.getFailt(ResultMessage.addShopNumError);
						}
						return ResultMessage.getFailt(ResultMessage.addShopNameError);
//					}
//					return ResultMessage.getFailt(ResultMessage.addShopIpError);
				}
				return result == null ? ResultMessage.getFailt(ResultMessage.parameterError) : result;
			default:
				return ResultMessage.getFailt("");
			}
		}
		return result;
	}

	@POST
	@Path("updateUser")
	public  String updateUser(String data, @Context HttpServletRequest request) {
		String result = this.validationParameter(data, request, userService, "username", "phonenum","remark", "useruuid");
		if (result == null) {
			JSONObject json = JsonUtils.converToJson(data);
			User user = this.userService.findByUserid(json.getString("useruuid"));
			if ( user != null) {
				switch (user.getUsertype()) {
				case 3:
				case 5:
					// 修改下游渠道商
					result = this.validationParameter(data, "downshopip", "", "provinceuuid", "credit",
							"downshopnum","");
					if(result == null){
						ProvincialInformation info = this.proService.findById(json.getString("provinceuuid"));

						DownShopInfo shop = this.downService.findShopInfoByUuid(json.getString("useruuid"));
						if(user.getUsertype() == 5){
							shop = this.downService.findOneBroadShop(json.getString("useruuid"));
						}
						if ( info != null && shop != null && shop.getUser().getUseruuid().equals(user.getUseruuid())) {
							// 检查ip是否重复
							DownShopInfo shopIp = this.downService.findShopIp(json.getString("downshopip"));
							if (shopIp == null || (shopIp != null && shopIp.getDownshopip().equals(json.getString("downshopip")) && shop.getDownshopuuid().equals(shopIp.getDownshopuuid()))) {
								// 检查商家名称 和商家编号是否存在
								User userName = this.userService.findUserName(json.getString("username"));
								if ((userName == null || ( userName != null && userName.getUsername().equals(json.getString("username"))) && user.getUseruuid().equals(userName.getUseruuid()))) {
//									DownShopInfo shopNum = this.downService.findShopNum(json.getString("downshopnum"));
//									if ((shopNum == null || ( shopNum != null && shopNum.getDownshopnum().equals(json.getString("downshopnum"))) && shop.getDownshopnum().equals(shopNum.getDownshopnum()))) {
										// 检查手机号码是否已经存在
//										User userPhone = this.userService.findOneUser(json.getString("phonenum"));
//										if (userPhone == null || (userPhone != null && userPhone.getPhonenum().equals(json.getString("phonenum")) && userPhone.getUseruuid().equals(user.getUseruuid()))) {
											user.setUsername(json.getString("username"));
											user.setRemark(json.getString("remark"));
											user.setPhonenum(json.getString("phonenum"));
											user.setWechatid(json.containsKey("wechatid") ? json.getString("wechatid") : "");
											shop.setDownshopip(json.getString("downshopip"));
											shop.setDownshopnum(json.getString("downshopnum"));
											shop.setModifytime(DateUtils.getNowDate());
											shop.setMerchantcredit(BigDecimal.ZERO);
											shop.setProvincialInformation(info);
											shop.setCredit(BigUtil.getBigDecimal(json.getString("credit")));
											shop.setOrderCallAddress(json.getString("orderCallAddress"));
											shop.setNoticeBalance(BigUtil.getBigDecimal(json.getString("noticeBalance")));
											if (this.downService.addDownShopInfo(shop, user)) {
												return ResultMessage.getSucceed(null);
											}
											return ResultMessage.getFailt("");
//										}
//										return ResultMessage.getFailt(ResultMessage.addUserError);
//									}
//									return ResultMessage.getFailt(ResultMessage.addShopNumError);
								}
								return ResultMessage.getFailt(ResultMessage.addShopNameError);
							}
							return ResultMessage.getFailt(ResultMessage.addShopIpError);
						}
						return ResultMessage.getFailt(ResultMessage.parameterError);
					}
					return  result;
				case 4:
					// 添加上游渠道商
					result = this.validationParameter(data, "appId", "provinceuuid", "shopnum","upshopuuid","orderCommitAddress","orderCallAddress","orderStatusAddress");
					if(result == null){
						UpShopInfo upshop = this.upService.findById(json.getString("upshopuuid"));
						ProvincialInformation info = this.proService.findById(json.getString("provinceuuid"));
						if (info != null && upshop != null) {
							// 检查ip是否重复
//							UpShopInfo shopIp = this.upService.findShopIp(json.getString("upshopip"));
//							if (shopIp == null || (shopIp != null && shopIp.getUpshopip().equals(json.getString("upshopip")) && shopIp.getUpshopuuid().equals(upshop.getUpshopuuid()))) {
								// 检查商家名称 和商家编号是否存在
								User userName = this.userService.findUserName(json.getString("username"));
								if (userName == null || (userName != null && userName.getUsername().equals(json.getString("username")) && userName.getUseruuid().equals(user.getUseruuid()))) {
//									UpShopInfo shopNum = this.upService.findShopNum(json.getString("shopnum"));
//									if (shopNum == null || (shopNum != null &&  shopNum.getShopnum().equals(json.getString("shopnum")) && shopNum.getUpshopuuid().equals(upshop.getUpshopuuid()))) {
										// 检查手机号码是否已经存在
//										User userPhone = this.userService.findOneUser(json.getString("phonenum"));
//										if (userPhone == null || (userPhone != null && userPhone.getPhonenum().equals(json.getString("phonenum")) && userPhone.getUseruuid().equals(user.getUseruuid()))) {
											user.setUsername(json.getString("username"));
											user.setRemark(json.getString("remark"));
											user.setPhonenum(json.getString("phonenum"));
											user.setWechatid(json.containsKey("wechatid") ? json.getString("wechatid") : "");
											upshop.setUpkey(json.getString("upkey"));
//											upshop.setUpshopip(json.getString("upshopip"));
											upshop.setAppId(json.getString("appId"));
											upshop.setShopnum(json.getString("shopnum"));
											upshop.setProvincialInformation(info);
											upshop.setOrderCommitAddress(json.getString("orderCommitAddress"));
//											upshop.setQueryBalanceAddress(json.getString("queryBalanceAddress"));
											upshop.setOrderCallAddress(json.getString("orderCallAddress"));
											upshop.setOrderStatusAddress(json.getString("orderStatusAddress"));
											upshop.setModifytime(DateUtils.getNowDate());
											upshop.setRepeatNum(json.getInt("repeatNum"));
											upshop.setNoticeBalance(BigUtil.getBigDecimal(json.getString("noticeBalance")));
											if (this.upService.addUpshopinfo(upshop, user)) {
												return ResultMessage.getSucceed(null);
											}
											return ResultMessage.getFailt("");
//										}
//										return ResultMessage.getFailt(ResultMessage.addUserError);
//									}
//									return ResultMessage.getFailt(ResultMessage.addShopNumError);
								}
								return ResultMessage.getFailt(ResultMessage.addShopNameError);
//							}
//							return ResultMessage.getFailt(ResultMessage.addShopIpError);
						}
						return ResultMessage.getFailt(ResultMessage.parameterError);
					}
					return result;
				default:
					return ResultMessage.getFailt("");
				}
			}
		}
		return result;
	}


	@SuppressWarnings("static-access")
	@POST
	@Path("addSystemUser")
	public String addSystemUser(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService, "username","phonenum","password","usertype","remark");
		if(result == null){
			String token = request.getHeader("token");
			if (token != null) {
				DecodedJWT jwt;
				try {
					jwt = JWT.decode(token);
					if (jwt != null) {
						JSONObject jsonJwt = JsonUtils.converToJson(jwt.getSubject());
						if (jsonJwt != null) {
							User login = userService.findByUserid(jsonJwt.getString(Config.tokenSignAttr));
							if(login != null && UserUtil.checkRoleSupper(login)){
								JSONObject json = JSONObject.fromObject(data);
								User user = this.userService.findUserName(json.getString("username"));
								if(user != null){
									return ResultMessage.getFailt( "用户名已经存在");
								}
								user = this.userService.findOneUser(json.getString("phonenum"));
								if(user == null){
									user = new User();
									user.setPhonenum(json.getString("phonenum"));
									user.setRemark(json.getString("remark"));
									user.setUsername(json.getString("username"));
									user.setUsertype(json.getInt("usertype"));
									user.setPassword(json.getString("password"));
									user.setUserstatus(1);
									user.setCreatetime(DateUtils.getNowDate());
									this.userService.addUser(user);
									return ResultMessage.getSucceed(null);
								}
								return ResultMessage.getFailt( "手机号已经存在");
							}else{
								return ResultMessage.getFailt( "没有权限");
							}
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
		return result;
	}

	@SuppressWarnings("static-access")
	@POST
	@Path("upadteSystemUser")
	public String upadteSystemUser(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService,"useruuid", "username","phonenum","password","usertype","remark");
		if(result == null){

			String token = request.getHeader("token");
			if (token != null) {
				DecodedJWT jwt;
				try {
					jwt = JWT.decode(token);
					if (jwt != null) {
						JSONObject jsonJwt = JsonUtils.converToJson(jwt.getSubject());
						if (jsonJwt != null) {
							User login = userService.findByUserid(jsonJwt.getString(Config.tokenSignAttr));
							if(login != null && UserUtil.checkRoleSupper(login)){
								JSONObject json = JSONObject.fromObject(data);
								User user = this.userService.findUserName(json.getString("username"));
								if(user != null && !user.getUseruuid().equals(json.getString("useruuid"))){
									return ResultMessage.getFailt( "用户名已经存在");
								}
								user = this.userService.findByUserid(json.getString("useruuid"));
								if(user != null){
									user.setPhonenum(json.getString("phonenum"));
									user.setRemark(json.getString("remark"));
									user.setUsername(json.getString("username"));
									user.setUsertype(json.getInt("usertype"));
									if(!StringUtils.isEmpty(json.getString("password"))){
										user.setPassword(json.getString("password"));
									}
									this.userService.addUser(user);
									return ResultMessage.getSucceed(null);
								}
								return ResultMessage.getFailt("");
							}
						}else{
							return ResultMessage.getFailt( "没有权限");
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
		return result;
	}


	@POST
	@Path("findUser")
	public String findUser(String data,@Context HttpServletRequest request){
		String result = this.validationParameterGetRole( request, userService);
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			Map<String, Object> parameters = MapUtil.getMap();
			if(!StringUtils.isEmpty(json.getString("shopName"))){
				parameters.put(":shopName", json.getString("shopName").concat("%"));
			}
			if(!StringUtils.isEmpty(json.getString("phonenum"))){
				parameters.put(":phonenum", json.getString("phonenum").concat("%"));
			}
			if(!StringUtils.isEmpty(json.getString("userstatus"))){
				parameters.put(":userstatus", json.getInt("userstatus"));
			}
			if(!StringUtils.isEmpty(json.getString("remark"))){
				parameters.put(":remark", json.getString("remark"));
			}
			//if(!StringUtils.isEmpty(json.getString("usertype"))){
			//	parameters.put(":usertype", json.getInt("usertype"));
			//}
			return ResultMessage.getSucceed( JsonUtils.excludes(this.userService.findPageUser(parameters,json.getInt("start"), json.getInt("pageSize")),
					new String[]{"errorCodesForUseruuid","lastlogintime","password","token","","wechatid"}));
		}
		return result;
	}

	@Path("findAllBroad")
	@POST
	public String findAllBroadDownShopInfo(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService,"useruuid");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			String token = request.getHeader("token");
			if (token != null) {
				DecodedJWT jwt;
				try {
					jwt = JWT.decode(token);
					if (jwt != null) {
						JSONObject jsonToken = JsonUtils.converToJson(jwt.getSubject());
						if (jsonToken != null) {
							User login = userService.findByUserid(jsonToken.getString(Config.tokenSignAttr));
							if(!UserUtil.checkRole(login)){
								return ResultMessage.getFailt("");
							}
							return ResultMessage.getSucceed( JsonUtils.jsonArrayToJson(this.userService.findShopBroadbandList( MapUtil.getMap()),
									new String[]{"phonenum","password","userstatus","usertype","token","lastlogintime","createtime","wechatid","remark",
											"provincialInformation","errorCodesForUseruuid","downshopip","downkey","downshopnum","createtime","status",
											"downshopbalance","merchantcredit","modifytime",""}));
						}
					}
				}catch (Exception e){
					e.printStackTrace();
				}
			}
		}
		return result;
	}


	@POST
	@Path("findUpUser")
	public String findUpUser(String data,@Context HttpServletRequest request){
		String result = this.validationParameterGetRole(request, userService);
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			Map<String, Object> parameters = MapUtil.getMap();
			if(!StringUtils.isEmpty(json.getString("shopName"))){
				parameters.put(":shopName", "%".concat(json.getString("shopName").concat("%")));
			}
			if(!StringUtils.isEmpty(json.getString("phonenum"))){
				parameters.put(":phonenum", json.getString("phonenum"));
			}
			if(!StringUtils.isEmpty(json.getString("userstatus"))){
				parameters.put(":userstatus", json.getInt("userstatus"));
			}
			if(json.containsKey("appid") && !StringUtils.isEmpty(json.getString("appid"))){
				parameters.put(":appid", json.getString("appid"));
			}
			if(json.containsKey("shopnum") && !StringUtils.isEmpty(json.getString("shopnum"))){
				parameters.put(":shopnum", json.getString("shopnum"));
			}
			if(json.containsKey("remark") && !StringUtils.isEmpty(json.getString("remark"))){
				parameters.put(":remark", json.getInt("remark"));
			}
			String token = request.getHeader("token");
			if (token != null) {
				DecodedJWT jwt;
				try {
					jwt = JWT.decode(token);
					if (jwt != null) {
						JSONObject jsonToken = JsonUtils.converToJson(jwt.getSubject());
						if (jsonToken != null) {
							User login = userService.findByUserid(jsonToken.getString(Config.tokenSignAttr));
							if(UserUtil.checkRoleSupper(login)){
								Page<UpShopInfo> upShopInfoPage = upService.findPageUpshopinfo(parameters,json.getInt("start"), json.getInt("pageSize"));
								return ResultMessage.getSucceed( JsonUtils.excludes(upShopInfoPage,
										new String[]{"errorCodesForUseruuid","lastlogintime","password","token","","wechatid","provincialInformation",""}));
							}else{
								return ResultMessage.getSucceed( JsonUtils.excludes(upService.findPageUpshopinfo(parameters,json.getInt("start"), json.getInt("pageSize")),
										new String[]{"errorCodesForUseruuid","lastlogintime","password","token","","wechatid","provincialInformation","upkey"}));
							}
						}
					}
				}catch(Exception e){
					e.printStackTrace();
				}
			}
		}
		return result;
	}

	@POST
	@Path("handleEnableShop")
	public String handleEnableShop(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService, "userstatus","useruuid");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			User user = this.userService.findByUserid(json.getString("useruuid"));
			if(user != null){
				user.setUserstatus(json.getInt("userstatus"));
				this.userService.updateShop(user);
				return ResultMessage.getSucceed(null);
			}
		}
		return result;
	}

	/**
	 * 删除用户
	 * @param data
	 * @param request
	 * @return
	 */
	@POST
	@Path("deleteUser")
	public String deleteUser(String data,@Context HttpServletRequest request){
		String result = this.validationParameter(data, request, userService, "userstatus","useruuid");
		if(result == null){
			JSONObject json = JsonUtils.converToJson(data);
			User user = this.userService.findByUserid(json.getString("useruuid"));
			if(user != null){
				user.setUserstatus(json.getInt("userstatus"));
				this.userService.updateShop(user);
				return ResultMessage.getSucceed(null);
			}
		}
		return result;
	}


//	@POST
//	@Path("handleEnableShopIsOpen")
//	public String handleEnableShopIsOpen(String data,@Context HttpServletRequest request){
//		String result = this.validationParameter(data, request, userService, "isOpen","useruuid");
//		if(result == null){
//			JSONObject json = JsonUtils.converToJson(data);
//			User user = this.userService.findByUserid(json.getString("useruuid"));
//			if(user != null){
//				user.setIsOpen(json.getInt("isOpen"));
//				this.userService.updateShop(user);
//				return ResultMessage.getSucceed(null);
//			}
//		}
//		return result;
//	}



}
